package com.sss.otep.ca.authentication;

import java.security.cert.X509Certificate;

import org.springframework.security.Authentication;
import org.springframework.security.AuthenticationException;
import org.springframework.security.AuthenticationManager;

public class OTEPAuthenticationManager implements AuthenticationManager {

	@Override
	public Authentication authenticate(Authentication authen)
			throws AuthenticationException {
		Object credentials = authen.getCredentials();
		if(X509Certificate.class.isAssignableFrom(credentials.getClass())){
			//X509Certificate certificate = (X509Certificate)credentials;
			//setupRightsBasedOn(certificate);
		}
		authen.setAuthenticated(true);
		return authen;
	}

//	private void setupRightsBasedOn( X509Certificate certificate ){
//
//	  X500Principal subjectX500Principal = certificate.getSubjectX500Principal();
//	  String str = subjectX500Principal.getName();
//	  System.out.println(str);
//	  Rights rights = rightsFor( commonNameFrom( subjectX500Principal.getName() ) );
//	  SecurityContext.initContext( rights );
//	}

//	private String commonNameFrom( String subjectName ) {
//	  return StringUtils.extractNesting(
//	      subjectName, "CN=", ",",
//	      EXCLUDE_OPEN_BRACE_IN_NESTING,
//	      EXCLUDE_CLOSING_BRACE_IN_NESTING );
//	}

}
